﻿define(['ko','repositories/repository.pageconfig','viewmodels/vm.footer', 
'viewmodels/vm.languagechooser', 'viewmodels/vm.link1', 'viewmodels/vm.bottomlinks', 
'viewmodels/vm.contactinfo', 'viewmodels/vm.logo', 'viewmodels/vm.mainmenu',
 'viewmodels/vm.pagepath', 'viewmodels/vm.pagetitle', 'viewmodels/vm.toplinks', 
 'viewmodels/vm.store','viewmodels/vm.cabinet'], 
function(ko, pageConfigRepo, vmFooter, vmLanguageChooser, vmLink1, vmBottomLinks, vmContactInfo, vmLogo, vmMainMenu, vmPagePath, vmPageTitle, vmTopLinks, vmStore, vmCabinet) {
	var getPageConfig = function(pageID) {
		var results = ko.observableArray();
		return $.Deferred(function(def) {
			$.when(pageConfigRepo.getPageConfig({
				results : results,
				param : {
					"pageid" : pageID
				}
			}).done(function() {
				setDataForTemplateModels(results()[0]);
				def.resolve();
			})).pipe(function() {

			}).fail(function() {
				def.reject();
			});

		}).promise();

	};
	var setDataForTemplateModels = function(data) {
		vmTopLinks.value(data.topLinks);
		var logo = {};
		logo[data.mooriConfigs['logo']] = true;
		vmLogo.value(logo);
		vmMainMenu.menus(data.menus);
		vmMainMenu.childMenus(data.childMenus);
		vmPageTitle.value(data.pageTitle);
		vmPagePath.value(data.pagePath);
		vmBottomLinks.value(data.bottomLinks);
		vmContactInfo.value(data.mooriConfigs['contactinfo']);
		vmFooter.value(data.mooriConfigs['footer']);
	};
	return {
		vmLink1 : vmLink1,
		vmBottomLinks : vmBottomLinks,
		vmContactInfo : vmContactInfo,
		vmLogo : vmLogo,
		vmMainMenu : vmMainMenu,
		vmPagePath : vmPagePath,
		vmPageTitle : vmPageTitle,
		vmTopLinks : vmTopLinks,
		vmLanguageChooser : vmLanguageChooser,
		vmFooter : vmFooter,
		store : vmStore,
		cabinet: vmCabinet,
		getPageConfig: getPageConfig
	};
});
